//
//  SameCityViewController.m
//  MM
//
//  Created by 郑渊文 on 6/2/15.
//  Copyright (c) 2015 王晨辉. All rights reserved.
//

#import "SameCityViewController.h"
#import "SameCityCell.h"
#import "InterpretationTwoViewController.h"

@interface SameCityViewController ()
{
    UIButton *backBtn;
}

@property(nonatomic,copy)NSMutableArray *palceArray;
@property(nonatomic,copy)NSMutableArray *startArray;
@property(nonatomic,copy)NSMutableArray *endArray;
@property(nonatomic,copy)NSMutableArray *activityIdArray;
@property(nonatomic,copy)UITableView *myTable;

@end

@implementation SameCityViewController


- (NSMutableArray *)palceArray
{
    if (nil == _palceArray)
    {
        _palceArray = [NSMutableArray array];
    }
    return _palceArray;
}

- (NSMutableArray *)startArray
{
    if (nil == _startArray)
    {
        _startArray = [NSMutableArray array];
    }
    return _startArray;
}

- (NSMutableArray *)endArray
{
    if (nil == _endArray)
    {
        _endArray = [NSMutableArray array];
    }
    return _endArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    _palceArray = [NSMutableArray array];
    _startArray = [NSMutableArray array];
    _endArray = [NSMutableArray array];
    _activityIdArray = [NSMutableArray array];
    
    

    
    
//    NSDictionary *param4 = @{@"userId":@"1",@"typeId":@"2"};
//    [UserDAL getHomePaternityActivityParams:param4 withBlock:^(NSDictionary *data, NSError *error) {
//        if (data) {
//            ////NSLog(@"what%@",data);
//            NSArray *array = data[@"dataList"];
//            for (NSDictionary *myDic in array) {
//                [_palceArray addObject:myDic[@"activityName"]];
//                [_startArray addObject:myDic[@"activityStartTime"]];
//                [_endArray  addObject:myDic[@"activityEndTime"]];
//                [_activityIdArray  addObject:myDic[@"activityId"]];
//            }
//            ////NSLog(@"name中得数据为%@",_palceArray);
//            
//            [_myTable reloadData];
//        }else
//        {
//            
//        }
//    }];

    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"ID"];
    NSDictionary *param44 = @{@"userId":ID};
    [UserDAL getMyEvaluationDetailItemsParams:param44 withBlock:^(NSArray *data, NSError *error) {
        
        
        numberArray = [NSMutableArray array];
        atrArray = [NSMutableArray array];
        timeArray = [NSMutableArray array];
        typeArray  = [NSMutableArray array];
        if (data.count!=0) {
            
            for (NSDictionary * dic in data) {
                
                NSString * activityId = [dic objectForKey:@"activityId"];
                NSString * activityName = [dic objectForKey:@"activityName"];
                NSString * isJoin = [dic objectForKey:@"activityStartTime"];
                NSString * timeStamp = [dic objectForKey:@"activityEndTime"];
                //            ////NSLog(@"%@,%@,%@,%@",position,activityName,isJoin,timeStamp);
                
                [numberArray addObject:isJoin];
                [timeArray addObject:timeStamp];
                [atrArray addObject:activityName];
                [typeArray addObject:activityId];
                
                
                
                ////NSLog(@"%@,%@,%@,",numberArray,timeArray,atrArray);
                
            }
            [_myTable reloadData];

            
        }else{
            
//            [JKAlert showMessage:@"提示" message:@""];
            alert(@"对不起，你所在的地区没有麦苗公学。");
            
        }
        
        
        
        
        
        
        
    }];
    

    
    self.navigationItem.title = @"同城解读";
    
    [self.navigationController.navigationBar setTranslucent:NO];//设置navigationbar的半透明
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#34bd81" alpha:1]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

//    _palceArray = [NSMutableArray arrayWithObjects:@"杭州小厕所",@"杭州小厕所",@"杭州小厕所",@"杭州小厕所",@"杭州小厕所", nil];
//    _startArray = [NSMutableArray arrayWithObjects:@"2012:3:98",@"2012:3:98",@"2012:3:98",@"2012:3:98",@"2012:3:98", nil];
//    _endArray = [NSMutableArray arrayWithObjects:@"2012:3:98",@"2012:3:98",@"2012:3:98",@"2012:3:98",@"2012:3:98", nil];
    [self initSubViews];
    // Do any additional setup after loading the view.
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    NSString *msg = [[NSString alloc] initWithFormat:@"您点击的是第%d个按钮!",buttonIndex];
    ////NSLog(@"msg:%@",msg);
    if (buttonIndex == 0) {
        
        [self dismissViewControllerAnimated:YES completion:nil];
        ////NSLog(@"1111111");
        
    }else if(buttonIndex == 1){
        
        
        ////NSLog(@"2222222");
        
        
    }
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)initSubViews
{
    
    //自定义左右按钮
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
     
                      forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(back)
     
     forControlEvents:UIControlEventTouchUpInside];
    
    button.frame = CGRectMake(0, 0, 20, 15);
    
    
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    _myTable = [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _myTable.delegate = self;
    _myTable.dataSource = self;
    _myTable.separatorStyle = UITableViewCellEditingStyleNone;
    [self.view addSubview:_myTable];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return atrArray.count;
}


#pragma mark--- tableViewDelegate 每行的高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60;
    
}
#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     static NSString *myCell = @"cell_identifier";
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCell];
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        _myTable.tableFooterView = [[UIView alloc]init];
        
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 59, SCREEN_WIDTH, 1)];
        view.backgroundColor = UIColorWithRGBA(229, 229, 231, 1);
        [cell addSubview:view];
        
        
        UILabel * typeLab = [[UILabel alloc]initWithFrame:CGRectMake(7/2, 0, SCREEN_WIDTH-7, 30)];
        typeLab.text = [NSString stringWithFormat:@"会场：%@",atrArray[indexPath.row]];
         typeLab.adjustsFontSizeToFitWidth = YES;
        typeLab.font = [UIFont systemFontOfSize:16];
        typeLab.textAlignment = NSTextAlignmentLeft;
        [cell addSubview:typeLab];
        
        
        UILabel * timeLab = [[UILabel alloc]initWithFrame:CGRectMake(7/2, 30, SCREEN_WIDTH-7, 20)];
        timeLab.text = [NSString stringWithFormat:@"时间：%@",timeArray[indexPath.row]];
         timeLab.adjustsFontSizeToFitWidth = YES;
        timeLab.font = [UIFont systemFontOfSize:12];
        timeLab.textAlignment = NSTextAlignmentLeft;
        [cell addSubview:timeLab];
        
        

    }
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    cell.placeLab.text= _palceArray[indexPath.row];
//    ////NSLog(@"是个什么鬼啊%@",cell.placeLab.text);
//    cell.startTime.text = _startArray[indexPath.row];
//    cell.endTime.text = _endArray[indexPath.row];
    
    
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    MyActivityDetailViewController *sugVC = [[MyActivityDetailViewController alloc]init];
//    sugVC.typeId = @"2";
//    sugVC.activityId = _activityIdArray[indexPath.row];
//    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:sugVC];
//    [self  presentViewController:nav animated:YES completion:nil];
    
    
    InterpretationTwoViewController * interVc = [[InterpretationTwoViewController alloc]init];
    interVc.activityId = typeArray[indexPath.row];
    interVc.dont = @"1";
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:interVc];
    [self  presentViewController:nav animated:YES completion:nil];
    
}


-(void)back
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
